/* ---------------------------------------------------------------------------
   (c) Copyright 2006 ActivIdentity, Inc.
   All Rights Reserved.

   This program is an unpublished copyrighted work which is proprietary
   to ActivIdentity. This computer program includes Confidential,
   Proprietary Information and is a Trade Secret of ActivIdentity.
   Any use, disclosure, modification and/or reproduction is prohibited
   unless authorized in writing by ActivIdentity.

   WARNING:  Unauthorized reproduction of this program as well as
   unauthorized preparation of derivative works based upon the
   program or distribution of copies by sale, rental, lease or
   lending are violations of federal copyright laws and state trade
   secret laws, punishable by civil and criminal penalties.
   --------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------
   Disclaimer

   ACTIVIDENTITY MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE 
   CONTENTS OR USE OF THIS SOFTWARE, AND SPECIFICALLY DISCLAIMS ANY EXPRESS
   OR IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR
   PURPOSE. Further, ActivIdentity reserves the right to revise this software
   and to make changes to its content, at any time, without obligation to
   notify any person or entity of such revisions or changes.
   --------------------------------------------------------------------------- */

#ifndef _ACINIT_H_
#define _ACINIT_H_

#if defined(WIN32)
#include <windows.h>
#else
#define CALLBACK
#endif

#ifdef	__cplusplus
extern "C" {
#endif

#define IN
#define OUT
#define INOUT

/***************/
/** CONSTANTS **/
/***************/
#define PORT_NAME_MAX_SIZE 80
#define ACINIT_GLOBAL_HANDLE 0

#define ACINIT_VERSION_VERSIONLEN	ACM_VERS_VERSIONLEN
#define ACINIT_VERSION_COPYRIGHTLEN	ACM_VERS_COPYRIGHTLEN
#define ACINIT_VERSION_COMMENTLEN	ACM_VERS_COMMENTLEN


/************/
/** MACROS **/
/************/
/* Accessors to retrieve the various parts of the version */
#define ACINIT_MAJOR_VERSION(x)	ACM_MAJOR_VERSION(x)
#define ACINIT_MINOR_VERSION(x)	ACM_MINOR_VERSION(x)
#define ACINIT_BUILD_VERSION(x)	ACM_BUILD_VERSION(x)


/**********************/
/** TYPE DEFINITIONS **/
/**********************/
typedef unsigned long ACINITHandle;

enum 
{
ACINIT_ERR_NOERROR						= 0, /* Success */
ACINIT_ERR_NOERROR_SDB_UPDATED			= 1, 
ACINIT_ERR_INTERNAL_ERROR				= 2, 
ACINIT_ERR_NOT_YET_IMPLEMENTED			= 3, 
ACINIT_ERR_NULL_POINTER					= 4, 
ACINIT_ERR_BAD_PARAMETER				= 5, 
ACINIT_ERR_CONTEXT_INVALID_HANDLE 		= 6, 
ACINIT_ERR_CONTEXT_MEMORY_ERROR 		= 7, 
ACINIT_ERR_MAX_CONCURRENT_CONNECTIONS_REACHED = 8, 
ACINIT_ERR_OPEN 						= 9, 
ACINIT_ERR_DETECT 						= 10, 
ACINIT_ERR_COMMUNICATION				= 11, 
ACINIT_ERR_ACCESS_DENIED				= 12, 
ACINIT_ERR_ACCESS_DENIED_PIN_NEEDED		= 13, 
ACINIT_ERR_INCORRECT_PIN				= 14, 
ACINIT_ERR_INITIALIZATION				= 15, 
ACINIT_ERR_LOAD_LIB 					= 16, 
ACINIT_ERR_READER_NOT_FOUND				= 17, 
ACINIT_ERR_READER_TYPE_UNKNOWN 			= 18, 
ACINIT_ERR_KEYWORD_PARAMETER_UNKNOWN	= 19, 
ACINIT_ERR_BUFFER_TOO_SMALL				= 20, 
ACINIT_ERR_ALLOCATED_BUFFER_EXPECTED	= 21, 
ACINIT_ERR_FUNCTION_NOT_APPLICABLE		= 22, 
ACINIT_ERR_SERIALNUMBER_INVALID			= 23, 
ACINIT_ERR_DEVICEMASK_INVALID			= 24, 
ACINIT_ERR_BAD_ACCESS_MODE				= 25,
ACINIT_ERR_MEMORY_ALLOC_FAILURE			= 26, 
ACINIT_ERR_UNKNOWN_PROFILE				= 27, 

/* SDB errors */
ACINIT_ERR_SDB_SERVICE_NOTFOUND			= 50, 
ACINIT_ERR_SDB_INVALID					= 51, 
ACINIT_ERR_SDB_GENERAL_DATA_NOTFOUND	= 52, 
ACINIT_ERR_SDB_ERR_INTERNALERROR		= 53,
ACINIT_ERR_SDB_ERR_NOTYETIMPLEMENTED	= 54,
ACINIT_ERR_SDB_ERR_BADMAGICNUMBER		= 55,
ACINIT_ERR_SDB_ERR_WRONGSDBVERSION		= 56,
ACINIT_ERR_SDB_ERR_INVALIDSDB			= 57,
ACINIT_ERR_SDB_ERR_MEMORYALLOCFAILURE	= 58,
ACINIT_ERR_SDB_ERR_INCOMPATIBLESDB		= 59,
ACINIT_ERR_SDB_ERR_WRONGSIZE			= 60,
ACINIT_ERR_SDB_ERR_WRONGBYTEORDER		= 61,
ACINIT_ERR_SDB_ERR_EMPTY_SDB			= 62,
ACINIT_ERR_SDB_ERR_ENDOFENUMERATION		= 63,
ACINIT_ERR_SDB_ERR_BADPARAM				= 64,
ACINIT_ERR_SDB_ERR_WRONG_KEY			= 65,
ACINIT_ERR_SDB_ERR_WRONG_MAC			= 66,
ACINIT_ERR_SDB_ERR_NEEDKEY				= 67,
ACINIT_ERR_SDB_ERR_NONCRYPTO_LIB		= 68,
ACINIT_ERR_SDB_ERR_CRYPTO				= 69,
ACINIT_ERR_SDB_ERR_SERVICEPARTNOTFOUND	= 70
};

enum
{
ACINIT_READER_TYPE_NO_READER			= -1,
ACINIT_READER_TYPE_TOKEN_ACTIVCOUPLER	= 0,
ACINIT_READER_TYPE_TOKENONE_CRADLE		= 1,
ACINIT_READER_TYPE_PCSC					= 2,
ACINIT_READER_TYPE_PCSC_JAVACARD		= 3,
ACINIT_READER_TYPE_MINITOKEN_CRADLE		= 4
};

enum
{
ACINIT_KEYWORD_PARAM_NBMAXTRANSMIT			= 0, /* Number of retransmissions allowed
													(default value: 3) */
ACINIT_KEYWORD_PARAM_TIMETORECEIVE			= 1, /* Time to wait for a response from the token reader 
													(default value: 500 milliseconds) */
ACINIT_KEYWORD_PARAM_TIMEWATCHDOG			= 2, /* Time to wait before assuming that the connection to the
													Reader is dead. (default value: 30,000 milliseconds) */
ACINIT_KEYWORD_PARAM_READERTYPE				= 3,  /* Reader type for the current session context */
ACINIT_KEYWORD_PARAM_READERNAME				= 4,  /* Reader name for the current session context */
ACINIT_KEYWORD_PARAM_DEVICE_MASK			= 5,  /* Device mask for the current session context */
ACINIT_KEYWORD_PARAM_DEVICE_SERIAL_NUMBER	= 6,   /* Device serial number for the current session context */
ACINIT_KEYWORD_PARAM_DEVICE_MASK_NUMBER		= 7,  /* Device mask number for the current session context */
ACINIT_KEYWORD_PARAM_DEVICE_KEYBOARD_SIZE	= 8,  /* Number of keys of the keyboard for the current session context */
ACINIT_KEYWORD_PARAM_DEVICE_BACKUP_BATTERY	= 9,  /* Backup battery present for the current session context (0=NO 1=YES)*/
ACINIT_KEYWORD_PARAM_DEVICE_BINARY_SERIAL_NUMBER = 10, /* Device serial number for the current session context (binary format) */
ACINIT_KEYWORD_PARAM_DEVICE_CLOCK		= 11 /* Device Clock present (Mini tokens) 0=no, 1=Yes */
};



/***************/
/** FUNCTIONS **/
/***************/
int CALLBACK acINITConnect (
		OUT ACINITHandle *pHandle,
		IN const char* pszReaderName,
		IN int nReaderType);

int CALLBACK acINITEnterPIN(
		IN ACINITHandle handle,
		IN const char *pszPIN);

int CALLBACK acINITSetParam(
		IN ACINITHandle handle,
		IN int nParamKeyword,
		IN unsigned long ulParamValueLength,
		IN void *pParamValue);

int CALLBACK acINITDisconnect(
		IN ACINITHandle  handle);

int CALLBACK acINITDetectReader(
		IN int nReaderType,
		IN const char *pszReaderName);

int CALLBACK acINITGetDetectedReadersList(
		IN int nReaderType,
		INOUT unsigned long *pulReadersListSize,
		OUT char *pszReadersList);

int CALLBACK acINITEraseAll(
		IN ACINITHandle handle,
		IN const char *pszEncryptionKey,
		IN SDB *psSDB);

int CALLBACK acINITEraseService(
		IN ACINITHandle handle,
		IN const char *pszEncryptionKey,
		IN const char *pszServiceName,
		IN SDB *psSDB);

int CALLBACK acINITGetParam(
		IN ACINITHandle handle,
		IN int nParamKeyword,
		INOUT unsigned long *pulParamValueLength,
		OUT void *pParamValue);

int CALLBACK acINITDownload (
		IN ACINITHandle handle,
		IN const char *pszEncryptionKey,
		INOUT SDB *psSDB);

long CALLBACK acINITGetVersion(	
		OUT char *pszVersion,
		OUT unsigned long *pulVersion,
		OUT char *pszCopy,
		OUT char *pszComment);

#ifdef	__cplusplus
}
#endif

#endif /* _ACINIT_H_ */
